package com.yhb.service.impl;

import com.yhb.model.ThirdPartyDeveloper;
import com.yhb.service.ThirdPartyService;
import lombok.var;
import me.edzh.spring.bootstrap.utils.ResultCode;
import me.edzh.spring.bootstrap.utils.exception.ServiceException;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Service
public class ThirdPartyServiceImpl implements ThirdPartyService {
    private final static Map<String, ThirdPartyDeveloper> sDevelopers = new HashMap<String, ThirdPartyDeveloper>() {{
        put("20359401", ThirdPartyDeveloper.builder()
                .appId("20359401")
                .aesKey("zMfVW4A1P8OEm52jmUdp7wPmxXfbEJ/4Nsrp5rjj8Mw=")
                .signSecret("GpTFLbTbTZ6YY0cmLEJgsPIikSo7DvJTZxuI+jmeKbM=")
                .build());
    }};

    @Override
    public ThirdPartyDeveloper getDeveloper(String appId) {
        return Optional.ofNullable(sDevelopers.get(appId)).orElseThrow(() -> new ServiceException(ResultCode.ERROR_PARAMETER_WRONG, "appId check failed"));
    }
}
